<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="120px" label-position="left" :disabled="!!isDetail" :rules="rules">
				<el-col :span="12">
					<el-form-item label="设备编码" prop="sbbm"  >
						<el-input v-model="dataForm.sbbm" placeholder="危险源编码（12位）+设备类型编码(2位)+3位流水码" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所属危险源名称" prop="sszdwxydymc" >
						<el-select v-model="dataForm.sszdwxydymc" placeholder="所属危险源名称" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sszdwxydymcOptions" :key="index" :label="item.ZDWXYMC" :value="item.ID" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<!--  -->
				<el-col :span="12">
					<el-form-item label="设备名称" prop="sbmc"  >
						<el-input v-model="dataForm.sbmc" placeholder="设备名称" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="设备类型" prop="sblx" >
						<el-select v-model="dataForm.sblx" placeholder="设备类型" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sblxOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="设备介质" prop="sbjz"  >
						<el-input v-model="dataForm.sbjz" placeholder="设备介质" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="运行状态" prop="sbyxzt"  >
						<el-select v-model="dataForm.sbyxzt" placeholder="运行状态" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sbyxztOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="是否核心参数" prop="sfhxcs" >
						<el-select v-model="dataForm.sfhxcs" placeholder="是否核心参数" :style='{"width":"100%"}' >
							<el-option v-for="(item) in sfhxcsOptions" :key="item.id" :label="item.fullName" :value="item.id" ></el-option>
							<!-- <el-option label="否得得" value="0"></el-option>
							<el-option label="是的的吧" value="1"></el-option> -->
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="生产单元类型" prop="scdylx"  >
						<el-select v-model="dataForm.scdylx" placeholder="生产单元类型" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in scdylxOptions" :key="index" :label="item.MC" :value="item.ID" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="生产装置编号" prop="sszzbh"  >
						<el-input v-model="dataForm.sszzbh" placeholder="生产装置编号" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="安装位置" prop="azwz" >
						<el-input v-model="dataForm.azwz" placeholder="安装位置" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="采集日期" prop="jcrq" >
						<el-date-picker v-model="dataForm.jcrq" placeholder="请选择" clearable :style='{"width":"100%"}' type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="安全等级" prop="aqjb"  >
						<el-select v-model="dataForm.aqjb" placeholder="安全等级" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in aqjbOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="坐标" prop="position"  >
						<el-select v-model="dataForm.position" placeholder="坐标" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in positionOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="采集类型" prop="cjlx"  >
						<el-select v-model="dataForm.cjlx" placeholder="采集类型" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in cjlxOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="采集数值" prop="cjsz" >
						<el-input v-model="dataForm.cjsz" placeholder="采集数值" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="是否连锁" prop="sflsbj"  >
						<el-select v-model="dataForm.sflsbj" placeholder="是否连锁" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sflsbjOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="报警状态" prop="bjzt"  >
						<el-select v-model="dataForm.bjzt" placeholder="报警状态" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in bjztOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="量程上限" prop="lcsx" >
						<el-input v-model="dataForm.lcsx" placeholder="量程上限" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="量程下限" prop="lcxx" >
						<el-input v-model="dataForm.lcxx" placeholder="量程下限" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="报警上上限" prop="bjzggx" >
						<el-input v-model="dataForm.bjzggx" placeholder="不填写" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="报警上限" prop="bjzgx" >
						<el-input v-model="dataForm.bjzgx" placeholder="报警上限" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="报警下下限" prop="bjzddx" >
						<el-input v-model="dataForm.bjzddx" placeholder="报警下下限" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="报警下限" prop="bjzdx" >
						<el-input v-model="dataForm.bjzdx" placeholder="报警下限" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="计量单位" prop="jldw"  >
						<el-input v-model="dataForm.jldw" placeholder="计量单位" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所属部位/单位" prop="sydw"  >
						<el-select filterable v-model="dataForm.sydw" placeholder="所属部位" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sydwOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="设备描述" prop="sbms"  >
						<el-input v-model="dataForm.sbms" placeholder="设备描述" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="报警描述" prop="bjms" >
						<el-input v-model="dataForm.bjms" placeholder="报警描述" clearable readonly :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
		dataFormNew: {},
        dataForm: {
					sbbm:undefined,
					sszdwxydymc:undefined,
					sbmc:undefined, //-
					sblx:undefined,
					sbjz:undefined,
					sbyxzt:undefined,
					sfhxcs:undefined,
					scdylx:undefined,
					sszzbh:undefined,
					azwz:undefined,
					jcrq:undefined,
					aqjb:undefined,
					position:undefined,
					cjlx:undefined,
					cjsz:undefined,
					sflsbj:undefined,
					bjzt:undefined,
					lcsx:undefined,
					lcxx:undefined,
					bjzggx:undefined,
					bjzgx:undefined,
					bjzddx:undefined,
					bjzdx:undefined,
					jldw:undefined,
					sydw:undefined,
					sbms:undefined,
					bjms:undefined,

        },
        rules: {
						sbbm:[
						{
							required:true,
							message:'请输入设备编码',
							trigger:'blur'
						},
						],
						sszdwxydymc:[
						{
							required:true,
							message:'请输入所属危险源名称',
							trigger:'blur'
						},
						],
						sbjz:[
						{
							required:true,
							message:'请输入设备介质',
							trigger:'blur'
						},
						],
						sbyxzt:[
						{
							required:true,
							message:'请输入运行状态',
							trigger:'blur'
						},
						],
						sfhxcs:[
						{
							required:true,
							message:'请输入是否核心参数',
							trigger:'blur'
						},
						],
						scdylx:[
						{
							required:true,
							message:'请输入生产单元类型',
							trigger:'blur'
						},
						],
						sszzbh:[
						{
							required:true,
							message:'请输入生产装置编号',
							trigger:'blur'
						},
						],
						aqjb:[
						{
							required:true,
							message:'请输入安全等级',
							trigger:'blur'
						},
						],
						position:[
						{
							required:true,
							message:'请输入坐标',
							trigger:'blur'
						},
						],
						cjlx:[
						{
							required:true,
							message:'请输入采集类型',
							trigger:'blur'
						},
						],
						sflsbj:[
						{
							required:true,
							message:'请输入是否连锁',
							trigger:'blur'
						},
						],
						bjzt:[
						{
							required:true,
							message:'请输入报警状态',
							trigger:'blur'
						},
						],
						jldw:[
						{
							required:true,
							message:'请输入计量单位',
							trigger:'blur'
						},
						],
						sydw:[
						{
							required:true,
							message:'请输入所属部位/单位',
							trigger:'blur'
						},
						],
						sbms:[
						{
							required:true,
							message:'请输入设备描述',
							trigger:'blur'
						},
						],

        },
				sszdwxydymcOptions:[],
				sblxOptions:[{"fullName":"温度","id":"0"},{"fullName":"压力","id":"1"},{"fullName":"液位","id":"2"},{"fullName":"流量","id":"3"},{"fullName":"ESD按钮","id":"4"},{"fullName":"气体","id":"5"},{"fullName":"其他","id":"6"}],
				sbyxztOptions:[{"fullName":"停用","id":"0"},{"fullName":"在用","id":"1"}],
				sfhxcsOptions:[{"fullName":"否","id":"0"},{"fullName":"是","id":"1"}],
				scdylxOptions:[],
				aqjbOptions:[{"fullName":"一级","id":"0"},{"fullName":"二级","id":"1"},{"fullName":"三级","id":"2"}],
				positionOptions:[{"fullName":"一级","id":"0"},{"fullName":"二级","id":"1"},{"fullName":"三级","id":"2"}],
				cjlxOptions:[{"fullName":"数字量","id":"0"},{"fullName":"模拟量","id":"1"}],
				sflsbjOptions:[{"fullName":"否","id":"0"},{"fullName":"是","id":"1"}],
				bjztOptions:[{"fullName":"报警","id":"0"},{"fullName":"正常","id":"1"}],
				sydwOptions:[],


      }
    },
    created() {
		this.getSszdwxydymcOptions();
		this.getScdylxOptions();
		this.getSydwOptions();

    },
    methods: {
		getSszdwxydymcOptions()
		{
			previewDataInterface('707f1102bce74818a551ebcfa88f2321').then(res => {
				this.sszdwxydymcOptions = res.data
			})
		},
		getScdylxOptions()
		{
			previewDataInterface('e7b2c31f5a7147c08629c5409dd7fdf4').then(res => {
				this.scdylxOptions = res.data
			})
		},
		getSydwOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.sydwOptions = res.data
			})
		},

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/JCZBYJ/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/JCZBYJ',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/JCZBYJ/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>